<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link th:href="@{/css/style.css}" rel="stylesheet" type="text/css" />
<script type="text/javascript" th:src="@{/js/jquery.js}"></script>
<script type="text/javascript">
function tipOpen(content) {
	$(".tipright p").text(content);
	$("#tip").fadeIn(200);
}
function tipClose() {
	$("#tip").fadeOut(200);
}
</script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>采购管理</li>
    <li>品牌管理</li>
    <li>基本内容</li>
  </ul>
</div>
<div class="rightinfo">
  <form action="" method="post">
    <ul class="tools">
      <li> 品牌名称:
        <input type="text" />
      </li>
      <li> 状态：
        <select>
          <option value="">请选择</option>
          <option value="1">可用</option>
          <option value="0">不可用</option>
        </select>
      </li>
      <li class="subBut" onclick="select()"><img th:src="@{/images/t06.png}" />查询</li>
      <li class="subBut" onclick="window.location.href='/purchase/brandAdd'"><img th:src="@{/images/t01.png}" />添加</li>
    </ul>
    <table class="tablelist">
<!--      <thead>-->
<!--        <tr>-->
<!--          <th>序号</th>-->
<!--          <th>品牌名称</th>-->
<!--          <th>状态</th>-->
<!--          <th>创建时间</th>-->
<!--          <th>创建人</th>-->
<!--          <th>操作</th>-->
<!--        </tr>-->
<!--      </thead>-->
<!--      <tbody>-->
<!--        <tr>-->
<!--          <td>1</td>-->
<!--          <td>联想</td>-->
<!--          <td>可用</td>-->
<!--          <td>2013-09-09 15:05:05</td>-->
<!--          <td>管理员</td>-->
<!--          <td>-->
<!--            <a href="/purchase/brandUpdate" class="tablelink">修改</a>-->
<!--            <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('是否确认注销此条信息？')">注销</a>-->
<!--          </td>-->
<!--        </tr>-->
<!--        <tr>-->
<!--          <td>2</td>-->
<!--          <td>海尔</td>-->
<!--          <td>不可用</td>-->
<!--          <td>2013-09-09 15:05:05</td>-->
<!--          <td>管理员</td>-->
<!--          <td>-->
<!--            <a href="/purchase/brandUpdate" class="tablelink">修改</a>-->
<!--            <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('是否确认恢复此条信息？')">恢复</a>-->
<!--          </td>-->
<!--        </tr>-->
<!--      </tbody>-->
    </table>
    <div class="pagin">
      <div class="message">共<i class="blue">1256</i>条记录，当前显示第&nbsp;<i class="blue">2&nbsp;</i>页</div>
      <ul class="paginList">
        <li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>
        <li class="paginItem"><a href="javascript:;">1</a></li>
        <li class="paginItem current"><a href="javascript:;">2</a></li>
        <li class="paginItem"><a href="javascript:;">3</a></li>
        <li class="paginItem"><a href="javascript:;">4</a></li>
        <li class="paginItem"><a href="javascript:;">5</a></li>
        <li class="paginItem more"><a href="javascript:;">...</a></li>
        <li class="paginItem"><a href="javascript:;">10</a></li>
        <li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>
      </ul>
    </div>
  </form>
  <!-- 提示框 -->
  <div id="tip" class="tip">
    <div class="tiptop"><span>提示信息</span><a onclick="tipClose()"></a></div>
    <div class="tipinfo"> <span><img th:src="@{/images/ticon.png}" /></span>
      <div class="tipright">
        <p></p>
        <cite>如果是请点击确定按钮 ，否则请点取消。</cite> </div>
    </div>
    <div class="tipbtn">
      <input name="" type="button"  class="sure" value="确定" onclick="tipClose();updateBrandStatus()" />
      &nbsp;
      <input name="" type="button"  class="cancel" value="取消" onclick="tipClose()" />
    </div>
  </div>
</div>
<script type="text/javascript">
    var pageNum;//页数
    var pageSize=5;//每页数量
    var totalPage;//总页数
    var totalRows;//总条数
	$('.tablelist tbody tr:odd').addClass('odd');
	$(function () {
	  pageNum=1;
	  select()
    })

    //查找品牌信息
	function select() {
	  var brand_status=$('select option:selected').val();
      var brandname=$('input').val();
      $.ajax({
        url: "/brand/selectbrand",
        async: false,
        type: "POST",
        data:{brandName:brandname,brandStatus:brand_status,pageNum:pageNum,pageSize:pageSize},
        dataType: "json",
        success: function (topicData) {
          pageNum=topicData.pageNum;
          totalPage=topicData.totalPage;
          totalRows=topicData.totalRows;
          var str="";
          str+="      <thead>\n" +
                  "        <tr>\n" +
                  "          <th>序号</th>\n" +
                  "          <th>品牌名称</th>\n" +
                  "          <th>状态</th>\n" +
                  "          <th>创建时间</th>\n" +
                  "          <th>创建人</th>\n" +
                  "          <th>操作</th>\n" +
                  "        </tr>\n" +
                  "      </thead>\n" +
                  "      <tbody>"
          if (topicData) {
            for (var i in topicData.data){
              str+="<tr>\n" +
                      "<td>"+topicData.data[i].brandId+"</td>\n" +
                      "<td>"+topicData.data[i].brandName+"</td>\n"
              if (topicData.data[i].brandStatus==0){
                str+="<td>不可用</td>\n"
              }else if (topicData.data[i].brandStatus==1){
                str+="<td>可用</td>\n"
              }
              str+="<td>"+topicData.data[i].createTime+"</td>\n" +
                      "<td>"+topicData.data[i].uname+"</td>\n" +
                      "<td>\n" +
                      "<a href=\"javascript:void(0)\" class=\"tablelink\" onclick=\"updateBrand()\">修改</a>\n"
              if (topicData.data[i].brandStatus==1){
                str+="<a href=\"javascript:void(0)\" class=\"tablelink\" onclick=\"tipOpen('是否确认注销此条信息？')\">注销</a>\n"
              }else if (topicData.data[i].brandStatus==0){
                str+="<a href=\"javascript:void(0)\" class=\"tablelink\" onclick=\"tipOpen('是否确认恢复此条信息？')\">恢复</a>\n"
              }
                str+="</td>\n" +
                      "</tr>"
            }
            str+="</tbody>"
            $(".tablelist").html(str)
            $(".tablelink").click(function () {
              var brandId=$(this).parent().siblings(":first").html();
              sessionStorage.setItem("brandId",brandId);
            })
            $(".message").children(":first-child").html(totalRows);
            $(".message").children(":last-child").html(pageNum);
          }
        }
      });
    }

    //点击恢复/注销改变品牌状态
    function updateBrandStatus() {
	  var brandId=sessionStorage.getItem("brandId");
      $.ajax({
        url: "/brand/updateBrandStatus",
        async: false,
        type: "POST",
        data: {brandId:brandId},
        dataType: "json",
        success: function (result) {
        }
      })
      select();
    }

    function updateBrand() {
      var brandId=$(this).parent().siblings(":first").html();
      sessionStorage.setItem("brandId",brandId);
      location.href="/purchase/brandUpdate";
    }
</script>
</body>
</html>
